[id].vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="admin--page-content">
  3. <div class="admin--sub--table--title">
  4. <p>{{ areaName ? `${areaName} 낚시어선 / 낚시터` : "낚시어선 / 낚시터" }}</p>
  5. <div class="sub--table--info">
  6. <span>🎣 낚시터 {{ fishingCount }}</span>
  7. <span>🚢 낚시어선 {{ onboardCount }}</span>
  8. </div>
  9. </div>
  10. <div class="admin--table-wrapper">
  11. <table class="admin--table">
  12. <thead>
  13. <tr>
  14. <th style="width: 80px;">번호</th>
  15. <th style="width: 140px;">구분</th>
  16. <th style="width: 180px;">분야</th>
  17. <th>이름</th>
  18. <th>주소</th>
  19. <th style="width: 100px;">제휴업체</th>
  20. <th style="width: 100px;">상태</th>
  21. <th style="width: 120px;">등록일</th>
  22. </tr>
  23. </thead>
  24. <tbody>
  25. <tr v-if="isLoading">
  26. <td colspan="8" class="admin--table-loading">데이터를 불러오는 중...</td>
  27. </tr>
  28. <tr v-else-if="!places || places.length === 0">
  29. <td colspan="8" class="admin--table-empty">해당 지역에 등록된 낚시어선/낚시터가 없습니다.</td>
  30. </tr>
  31. <tr
  32. v-else
  33. v-for="(p, index) in places"
  34. :key="p.place_type + '-' + p.id"
  35. class="admin--table-row-clickable"
  36. @click="goToPlace(p)"
  37. >
  38. <td class="date">{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  39. <td>
  40. <span :class="['admin--badge', p.place_type === 'onboard' ? 'admin--badge-active' : 'admin--badge-html']">
  41. {{ p.place_type === "onboard" ? "낚시어선" : "낚시터" }}
  42. </span>
  43. </td>
  44. <td>{{ p.field_name || "-" }}</td>
  45. <td class="admin--table-title">{{ p.name }}</td>
  46. <td>{{ p.address || "-" }}</td>
  47. <td>
  48. <span v-if="p.partnership_YN === 'Y'" class="admin--badge admin--badge-active">제휴</span>
  49. <span v-else>-</span>
  50. </td>
  51. <td>
  52. <span :class="['admin--badge', p.status_YN === 'Y' ? 'admin--badge-active' : 'admin--badge-ended']">
  53. {{ p.status_YN === "Y" ? "사용중" : "미사용" }}
  54. </span>
  55. </td>
  56. <td class="date">{{ formatDate(p.created_at) }}</td>
  57. </tr>
  58. </tbody>
  59. </table>
  60. </div>
  61. <div class="admin--place--btn--wrap">
  62. <!-- 버튼 영역 -->
  63. <div class="admin--form-actions">
  64. <button type="button" class="admin--btn" @click="goBack">
  65. ← 지역 상세로
  66. </button>
  67. </div>
  68. <!-- 페이지네이션 -->
  69. <div v-if="totalPages > 1" class="admin--pagination">
  70. <button
  71. v-if="totalPages > 2"
  72. class="admin--pagination-btn"
  73. :disabled="currentPage === 1"
  74. @click="changePage(1)"
  75. title="처음"
  76. >◀◀</button>
  77. <button
  78. class="admin--pagination-btn"
  79. :disabled="currentPage === 1"
  80. @click="changePage(currentPage - 1)"
  81. title="이전"
  82. >◀</button>
  83. <button
  84. v-for="page in visiblePages"
  85. :key="page"
  86. class="admin--pagination-btn"
  87. :class="{ 'is-active': page === currentPage }"
  88. @click="changePage(page)"
  89. >{{ page }}</button>
  90. <button
  91. class="admin--pagination-btn"
  92. :disabled="currentPage === totalPages"
  93. @click="changePage(currentPage + 1)"
  94. title="다음"
  95. >▶</button>
  96. <button
  97. v-if="totalPages > 2"
  98. class="admin--pagination-btn"
  99. :disabled="currentPage === totalPages"
  100. @click="changePage(totalPages)"
  101. title="끝"
  102. >▶▶</button>
  103. </div>
  104. </div>
  105. </div>
  106. </template>
  107. <script setup>
  108. import { ref, computed, onMounted } from "vue";
  109. import { useRoute, useRouter } from "vue-router";
  110. definePageMeta({
  111. layout: "admin",
  112. middleware: ["auth"],
  113. });
  114. const route = useRoute();
  115. const router = useRouter();
  116. const { get } = useApi();
  117. const areaId = route.params.id;
  118. const isLoading = ref(false);
  119. const places = ref([]);
  120. const areaName = ref("");
  121. const onboardCount = ref(0);
  122. const fishingCount = ref(0);
  123. const currentPage = ref(1);
  124. const perPage = ref(10);
  125. const totalCount = ref(0);
  126. const totalPages = ref(0);
  127. // 페이지네이션 표시 페이지 번호
  128. const visiblePages = computed(() => {
  129. const pages = [];
  130. const maxVisible = 5;
  131. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
  132. let end = Math.min(totalPages.value, start + maxVisible - 1);
  133. if (end - start < maxVisible - 1) start = Math.max(1, end - maxVisible + 1);
  134. for (let i = start; i <= end; i++) pages.push(i);
  135. return pages;
  136. });
  137. // 데이터 로드
  138. const loadPlaces = async () => {
  139. isLoading.value = true;
  140. const { data, error } = await get(`/area/${areaId}/places`, {
  141. params: { page: currentPage.value, per_page: perPage.value },
  142. });
  143. if (!error && data?.success && data?.data) {
  144. places.value = data.data.items || [];
  145. areaName.value = data.data.area_name || "";
  146. onboardCount.value = data.data.onboard_count || 0;
  147. fishingCount.value = data.data.fishing_count || 0;
  148. totalCount.value = data.data.total || 0;
  149. totalPages.value = data.data.total_pages || 0;
  150. }
  151. isLoading.value = false;
  152. };
  153. // 페이지 변경
  154. const changePage = (page) => {
  155. if (page < 1 || page > totalPages.value) return;
  156. currentPage.value = page;
  157. loadPlaces();
  158. window.scrollTo({ top: 0, behavior: "smooth" });
  159. };
  160. // 이동
  161. const goToPlace = (p) => {
  162. if (p.place_type === "onboard") {
  163. router.push(`/site-manager/onboard/detail/${p.id}`);
  164. } else if (p.place_type === "fishing") {
  165. router.push(`/site-manager/fishing/detail/${p.id}`);
  166. }
  167. };
  168. const goBack = () => router.push(`/site-manager/area/detail/${areaId}`);
  169. // 날짜만
  170. const formatDate = (dateString) => {
  171. if (!dateString) return "-";
  172. const date = new Date(dateString.replace(" ", "T"));
  173. if (isNaN(date.getTime())) return dateString;
  174. return date.toLocaleDateString("ko-KR", { year: "numeric", month: "2-digit", day: "2-digit" });
  175. };
  176. onMounted(() => {
  177. loadPlaces();
  178. });
  179. </script>